package design.mode.effective_java.chapter8.item52;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
import java.util.*;

/**
 * @author ZhongMingde on 2021/8/31
 */

// 坏了!-这个程序打印什么?
public class CollectionClassifier {
    public static String classify(Set<?> s) {
        return "Set";
    }

    public static String classify(List<?> lst) {
        return "List";
    }

    public static String classify(Collection<?> c) {
        return c instanceof Set ? "Set" : c instanceof List ? "List" : "Unknown Collection";
    }

    public static void main(String[] args) throws IOException {
        Collection<?>[] collections = {
                new HashSet<String>(), new ArrayList<BigInteger>(), new HashMap<String,String>().values()
        };
        for (Collection<?> c : collections) {
            System.out.println(classify(c));
        }
//        try (ObjectOutputStream objectOutputStream = new ObjectOutputStream()) {
//            objectOutputStream.write();
//        }
    }
}
